package com.tvsinfo.jdk.demo.case8_fork_join;

import java.util.List;
import java.util.concurrent.RecursiveTask;

/**
 * @Author ruyi.song
 * @Date 2019/12/27 16:18:32
 */
public class OrderQueryApi extends RecursiveTask<List> {
    private static final int threshold = 10;// 阈值
    /**
     * start开始查询页码，end结束查询页码
     */
    final int start, end;
    public OrderQueryApi(int start, int end) {
        this.start = start;
        this.end = end;
    }
    String black="     ";
    /**
     *
     */
    @Override
    protected List compute() {
        boolean compute = (end - start) <= threshold;
        if (compute) {
            SQLSelectDao sqlSelectDao = new SQLSelectDao();
            return sqlSelectDao.selectOrderInfoList(start, end);
        } else {
            int mid = (end +start ) / 2;
            OrderQueryApi f1 = new OrderQueryApi(start, mid);
            f1.fork();
            OrderQueryApi f2 = new OrderQueryApi(mid+1, end);
            f2.fork();
            System.out.println("------拆分  left: start:"+start+" end:"+mid+" right: start:"+(mid+1)+" end:"+end);
            List list1 = f1.join();
            list1.addAll(f2.join());
            return list1;
        }
    }
}
